﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;

namespace HyperlinksWeb
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class browserService : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            // get url passed in, pre-pend "http://" if needed
            string url = context.Request.Headers["url"];
            if (url.StartsWith("www", StringComparison.OrdinalIgnoreCase))
            {
                url = "http://" + url;
            }

            // get url content and write into response
            System.Net.WebClient c = new System.Net.WebClient();
            try
            {
                var data = c.DownloadData(url);
                var str = Encoding.UTF8.GetString(data);
                context.Response.Write(str);
            }
            catch
            {
                context.Response.Write(string.Format("Sorry, '{0}' not found.", url));
            }
        }
        public bool IsReusable
        {
            get { return true; }
        }
    }
}
